<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php echo $commander->getListCommandsPanel('sa-a-d', ''); ?>
<div class="menu_list">
	<table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
            <tr>
                <th class="first center">&nbsp;&nbsp;<?php echo ucfirst($txt->getWord('id')); ?>&nbsp;&nbsp;</th>
                <th><?php echo ucfirst($txt->getWord('choose')); ?></th>
                <th>&nbsp;</th>
	            <th colspan="2">&nbsp;&nbsp;#&nbsp;&nbsp;<?php echo ucfirst($txt->getWord('order')); ?></th>
                <?php if ($shop->getGlobalSetting('groups')): ?>
                <th><?php echo ucfirst($txt->getWord('product')).' '.ucfirst($txt->getWord('group')); ?></th>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('categories')): ?>
                <th><?php echo ucfirst($txt->getWord('category')); ?></th>
                <?php endif; ?>
                <th><?php echo ucfirst($txt->getWord('title')); ?></th>
                <?php if ($shop->getGlobalSetting('use_tax')): ?>
               	<th><?php echo ucfirst($txt->getWord('tax')).' '.ucfirst($txt->getWord('group')); ?></th>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('variations') == false): ?>
                <th><?php echo ucfirst($txt->getWord('description')); ?></th>
                <th><?php echo ucfirst($txt->getWord('identity')); ?></th>
                <th><?php echo ucfirst($txt->getWord('ext_identity')); ?></th>
					<?php if($shop->GlobalSettings['shipping_weight_volume_active']): ?>
					<th><?php echo ucfirst($txt->getWord('length')); ?></th>
					<th><?php echo ucfirst($txt->getWord('width')); ?></th>
					<th><?php echo ucfirst($txt->getWord('height')); ?></th>
					<?php endif; ?>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('simple_price_model')): ?>
                <th><?php echo ucfirst($txt->getWord('price')); ?></th>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('product_sale_hours')): ?>
                <th><?php echo ucfirst($txt->getWord('start')); ?></th>
                <th><?php echo ucfirst($txt->getWord('end')); ?></th>
                <?php endif; ?>
                <!--
                <th colspan="2"><?php echo ucfirst($txt->getWord('activation')); ?></th>
                <th colspan="2"><?php echo ucfirst($txt->getWord('deactivation')); ?></th>-->
                <th><?php echo ucfirst($txt->getWord('active')); ?></th>
                <th><?php echo ucfirst($txt->getWord('edit')); ?></th>
				<th><?php echo ucfirst($txt->getWord('frontpage')); ?></th>
                <th class="last"><?php echo ucfirst($txt->getWord('delete')); ?></th>
            </tr>
        </thead>
        <tbody>
        	<tr class="items">
	            <td class="first center"><img 	title="<?php echo ucfirst($txt->getWord('new')); ?>"
                                                class="icon command" 
                                                src="<?php echo SYSICONS_URL; ?>add_16.gif" 
                                                onclick="if(document.getElementById('new_product_title').value != '') { edit_form.submit(); }" /></td>
	            <td><input title="<?php echo ucfirst($txt->getWord('all')); ?>" class="select_all" type="checkbox" name="select_all" value="" /></td>
	            <td>&nbsp;</td>
                <td colspan="2">&nbsp;</td>
                <?php if ($shop->getGlobalSetting('groups')): ?>
                <td>
                    <select class="small" name="new_product_group" >
						<option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('group')); ?></option>
                        <?php
                        if($shop->getGroups())
                        {
                            foreach($shop->getGroups() as $group)
                            { echo '<option value="'.$group->getId().'">'.$group->getTitle().'</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('categories')): ?>
             	<td>
                    <select class="small" name="new_product_cat" >
                    	<option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('category')); ?></option>
						<?php
                        if($shop->getCats())
                        {
                            foreach($shop->getCats() as $cat)
                            { echo '<option value="'.$cat->getId().'">'.$cat->getTitle().'</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
	            <td><input class="small-m" name="new_product_title" type="text" value="" maxlength="50" id="new_product_title" /></td>
                <?php if ($shop->getGlobalSetting('use_tax')): ?>
                <td>
                    <select name="new_product_tax" class="small"> 
                        <option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('tax').' '.$txt->getWord('group')); ?></option>
                        <?php
                        if($shop->getTaxGroups())
                        {
                            foreach($shop->getTaxGroups() as $tax)
                            { echo '<option value="'.$tax['id'].'" '.getIsSelectedHTML($tax['id'], $shop->GlobalSettings['default_tax_id']).'>'.$tax['title'].' ('.(($tax['tax']-1)*100).'%)</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('simple_price_model')): ?>
                <td>&nbsp;</td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('product_sale_hours')): ?>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('variations') == false): ?>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
				<?php if($shop->GlobalSettings['shipping_weight_volume_active']): ?>
				<td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
				<?php endif; ?>
                <?php endif; ?>
	            <td colspan="4">&nbsp;</td>
	            <td class="last"></td>
	        </tr>
            <?php
            if($shop->getProductList()):
            foreach($shop->getProductList() as $product)
            {
            ?>
            <tr class="items">
            	<td class="first center"><?php echo $product->getId(); ?><input type="hidden" name="p_id[]" value="<?php echo $product->getId(); ?>" /></td>
                <td><input class="select_list" type="checkbox" name="selected[]" value="<?php echo $product->getId(); ?>" /></td>
                <td><a title="Preview" href="<?php echo SITE_URL; ?>?p=<?php echo $product->getId(); ?>" target="_blank"><img class="icon" src="<?php echo SYSICONS_URL; ?>product_16.gif" alt="product" ref="product" /></a></td>
                <td>
					<select name="ProductOrder[]" class="xsmall">
						<?php 
						for($i = 0; $i <= count($shop->getProductList()); $i++)
						{
							?>
							<option value="<?php echo $i; ?>" <?php echo getIsSelectedHTML($i, $product->getProductOrder()); ?>>#<?php echo ($i+1); ?></option>
							<?php
						}
						?>
					</select>
				</td>
				<td class="center">
                    <?php //echo $commander->getCommandButton('up', $product->getId()); ?>
                    <?php //echo $commander->getCommandButton('down', $product->getId()); ?>
                </td>
                <?php if ($shop->getGlobalSetting('groups')): ?>
                <td>
                    <select class="small" name="p_group_id[]" >
						<option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('group')); ?></option>
                        <?php
                        if($shop->getGroups())
                        {
                            foreach($shop->getGroups() as $group)
                            { echo '<option value="'.$group->getId().'" '.getIsSelectedHTML($group->getId(), $product->getGroupId()).'>'.$group->getTitle().'</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('categories')): ?>
             	<td>
                    <select class="small" name="p_cat_id[]" onchange="submit();">
                    	<option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('category')); ?></option>
						<?php
                        if($shop->getCats())
                        {
                            foreach($shop->getCats() as $cat)
                            { echo '<option value="'.$cat->getId().'" '.getIsSelectedHTML($cat->getId(), $product->getCatId()).'>'.$cat->getTitle().'</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <td><input class="small-m" name="p_title[]" type="text" value="<?php echo $product->getTitle(); ?>" maxlength="50" /></td>
                <?php if ($shop->getGlobalSetting('use_tax')): ?>
                <td>
                    <select name="p_tax_id[]" class="small"> 
                        <option value="0"><?php echo ucfirst($txt->getWord('select')).' '.ucfirst($txt->getWord('tax').' '.$txt->getWord('group')); ?></option>
                        <?php
                        if($shop->getTaxGroups())
                        {
                            foreach($shop->getTaxGroups() as $tax)
                            { echo '<option value="'.$tax['id'].'" '.getIsSelectedHTML($tax['id'], $product->getTaxId()).'>'.$tax['title'].' ('.(($tax['tax']-1)*100).'%)</option>'; }
                        }
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('variations') == false): ?>
                <td>
                	<input class="max_200 small var_val" type="text" name="var_title[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getVarTitle(); ?>" id="var_title_<?php echo $product->getFirstVariationId(); ?>" />
                </td>
                <td>
                	<input class="max_40 xsmall var_val" type="text" name="identity[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getIdentity(); ?>"  />
                </td>
                <td>
                	<input class="max_40 xsmall var_val" type="text" name="ext_identity[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getExtIdentity(); ?>"  />
                </td>
                <?php if($shop->GlobalSettings['shipping_weight_volume_active']): ?>
                <td>
                	<input class="max_9 xxsmall numeric int var_val" type="text" name="length[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getLength(); ?>"  />
                </td>
                <td>
                	<input class="max_9 xxsmall numeric int var_val" type="text" name="width[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getWidth(); ?>"  />
                </td>
                <td>
                	<input class="max_9 xxsmall numeric int var_val" type="text" name="height[]" value="<?php echo $product->Variations[$product->getFirstVariationId()]->getHeight(); ?>"  />
                </td>
				<?php endif; ?>
                <?php endif; ?>
                <?php if ($shop->getGlobalSetting('simple_price_model')): ?>
                <td><input class="xsmall numeric" name="p_price[]" type="text" value="<?php echo $product->getPrice(false); ?>" /></td>
                <?php endif; ?>
                <?php if($shop->getGlobalSetting('product_sale_hours')): ?>
                <td>
                	<select name="SaleStartHour[]" class="xsmall" onchange="submit();"> 
                        <option value="0">00:00</option>
                        <?php
						for($i=0; $i < 24; $i++)
						{
							$text = $i;
							if($i < 10)
							{ $text = '0'.$text; }
							echo '<option value="'.$i.'" '.getIsSelectedHTML($i, $product->getSaleStartHour()).'>'.$text.':00</option>';
						}
                        ?>
                    </select>
                </td>
                <td>
                	<select name="SaleEndHour[]" class="xsmall" onchange="submit();"> 
                        <option value="0">00:00</option>
                        <?php
						for($i=0; $i < 24; $i++)
						{
							$text = $i;
							if($i < 10)
							{ $text = '0'.$text; }
							echo '<option value="'.$i.'" '.getIsSelectedHTML($i, $product->getSaleEndHour()).'>'.$text.':00</option>';
						}
                        ?>
                    </select>
                </td>
                <?php endif; ?>
                <td>
                	<?php echo $commander->getActivationFieldsObject($product); ?>
                    <input type="hidden" name="p_active[]" value="<?php echo $product->getActive(); ?>" />
                </td>
                <td class="center">
                	<a href="<?php echo $commander->getFormAction(); ?>&amp;item=<?php echo $product->getId(); ?>"><img title="<?php echo ucfirst($txt->getWord('edit')); ?>" class="icon command" src="<?php echo SYSICONS_URL; ?>configure_16.gif" /></a>
                </td>
				<td>
                    <select name="FrontpageDisplay[]" class="xsmall"> 
                        <option value="0" <?php echo getIsSelectedHTML(0, $product->getFrontpageDisplay()); ?>><?php echo ucfirst($txt->getWord('no')); ?></option>
						<option value="1" <?php echo getIsSelectedHTML(1, $product->getFrontpageDisplay()); ?>><?php echo ucfirst($txt->getWord('yes')); ?></option>
                    </select>
                </td>
                <td class="last">
               		<img title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('product')); ?>" class="icon command delete_p" src="<?php echo SYSICONS_URL; ?>delete_16.gif" onclick="deleteDialog(<?php echo $product->getId(); ?>);" />
                </td>
            </tr>
            <?php
            }
            ?>
            <?php endif; ?>
        </tbody>
    </table>
    <input type="hidden" name="delete_p" id="del_p_id" value="0" />
</div>
<script type="text/javascript">
function deleteDialog(productId)
{
	jQuery('#delete_dialog').dialog('open');
	jQuery('#delete_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('product')); ?>': function() 
			{
				jQuery('#del_p_id').val(productId);
				jQuery(this).dialog('close');
				jQuery('#edit_form').submit();
			}
		}
	});
}
</script>
<div id="delete_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('product')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete')); ?></p>
</div>